﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Client_Server_Interface
{
    public class Support
    {
        public static Double CoordinatesToDouble(string coordinates)
        {
            int first = coordinates.Length - 4;
            double h = 0;
            double m;
            double s;
            switch (coordinates.Length)
            {
                case 6:
                    h = double.Parse(coordinates.Remove(2));
                    break;
                case 7:
                    h = double.Parse(coordinates.Remove(3));
                    break;
                case 8:
                    h = double.Parse(coordinates.Substring(1, 3));
                    break;
                default:
                    //IncorrectInputValueException.Throw("Coordinates length", coordinates);
                    return 0;
                    break;

            }
            m = int.Parse(coordinates.Substring(first, 2));
            s = int.Parse(coordinates.Substring(first + 2, 2));
            double ret = h + m/60 + s/3600;
            return ret;
        }

        public static byte[] LengthToBytes(int length)
        {
            return BitConverter.GetBytes(length);
        }
    }
}
